package com.byxm.wlgw.query;

import com.byxm.wlgw.bean.XxBean;

public class XxQuery {
	/**
	 * 查找选项信息、不需要分页
	 */
	public String findXxQuery(){
		StringBuffer sql=new StringBuffer();
		sql.append("select * from xx where xxlx=0 order by fxxid,px");
		return sql.toString();
	}
	
	/**
	 * 查找菜单
	 */
	public String findXxQueryByXx(XxBean xxBean){
		StringBuffer sql=new StringBuffer();
		sql.append("select * from xx where xxlx=0");
		if(xxBean.getXxid()==null){
			sql.append(" and fxxid=0");
		}
		if(xxBean.getXxid()!=null){
			sql.append(" and fxxid=").append(xxBean.getXxid());
		}
		sql.append("order by fxxid,px");
		return sql.toString();
	}
	/**
	 * 保存菜单
	 */
	public String saveXx(XxBean xxBean){
		StringBuffer sql=new StringBuffer();
		if(xxBean.getXxid()==null&&xxBean.getFxxid()==0){//父菜单 的保存
			sql.append("insert into xx(xxm,fxxid,xxlx,px)values('");
			sql.append(xxBean.getXxm()).append("',0,0,").append(xxBean.getPx()).append(")");
		}
		if(xxBean.getXxid()==null&&xxBean.getFxxid()!=0){
			sql.append("insert into xx(xxm,fxxid,xxlx,px,xxurl)values('");
			sql.append(xxBean.getXxm()).append("',").append(xxBean.getFxxid()).append(",0,").append(xxBean.getPx());
			sql.append(",'").append(xxBean.getXxurl()).append("'");
			sql.append(")");
		}
		return sql.toString();
	}
	public String deletefXx(XxBean xxBean){
		StringBuffer sql=new StringBuffer();
		sql.append("delete from xx where xxid=").append(xxBean.getXxid());
		sql.append(" or fxxid=").append(xxBean.getXxid());
		return sql.toString();
	}
	
}
